home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / pmlsrc / poly.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  2.2 KB  |  96 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FUNCTION
  23.  *
  24.  *    poly   double precision polynomial evaluation
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    poly
  29.  *    machine independent routines
  30.  *    math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *    Evaluates a polynomial and returns double precision
  35.  *    result.  Is passed a the order of the polynomial,
  36.  *    a pointer to an array of double precision polynomial
  37.  *    coefficients (in ascending order), and the independent
  38.  *    variable.
  39.  *
  40.  *  USAGE
  41.  *
  42.  *    double poly (order, coeffs, x)
  43.  *    int order;
  44.  *    double *coeffs;
  45.  *    double x;
  46.  *
  47.  *  PROGRAMMER
  48.  *
  49.  *    Fred Fish
  50.  *
  51.  *  INTERNALS
  52.  *
  53.  *    Evalates the polynomial using recursion and the form:
  54.  *
  55.  *        P(x) = P0 + x(P1 + x(P2 +...x(Pn)))
  56.  *
  57.  */
  58.  
  59. #if defined (__M68881__) && !defined (_M68881)
  60. /*# define _M68881*/
  61. #endif
  62.  
  63. #include <stdio.h>
  64. #include <math.h>
  65. #include "pml.h"
  66.  
  67.  
  68. double poly (order, coeffs, x)
  69. register int order;
  70. double *coeffs;
  71. double x;
  72. {
  73.     double curr_coeff;
  74.     double rtn_value;
  75.  
  76.     DBUG_ENTER ("poly");
  77.     DBUG_5 ("polyin", "args %d %#x %le", order, coeffs, x);
  78. #if 0
  79.     if (order <= 0) {
  80.     rtn_value = *coeffs;
  81.     } else {
  82.     curr_coeff = *coeffs;    /* Bug in Unisoft's compiler.  Does not */
  83.     coeffs++;        /* generate good code for *coeffs++ */
  84.     rtn_value = curr_coeff + x * poly (--order, coeffs, x);
  85.     }
  86. #else /* ++jrb -- removed tail recursion */
  87.     coeffs += order;
  88.     rtn_value = *coeffs--;
  89.     while(order-- > 0)
  90.     rtn_value = *coeffs-- + (x * rtn_value);
  91.  
  92. #endif
  93.     DBUG_3 ("polyout", "result %le", rtn_value);
  94.     DBUG_RETURN (rtn_value);
  95. }
  96.